13. Network
Reflection
Group Assignment
Attached is the link to group assignment
Individual Assignment
Learning from Interfacing and Networking
Through this project, I have learned the intricacies of Serial and TWI communications. Serial communication was pivotal for interfacing with the computer for debugging purposes, while TWI enabled direct MCU-to-MCU interaction. Below is a table summarizing the key commands and concepts:
Concept | Description | Key Commands |
---|---|---|
Serial Communication | Enables data transfer between the MCU and a computer or other serial devices. | Serial.begin(115200); Serial.println("message"); |
Serial Data Handling | Reading incoming serial data from the computer. | if (Serial.available()) char c = Serial.read(); |
TWI/I2C Communication | Multi-master, multi-slave, packet-switched communication protocol. | Wire.begin(); (master)Wire.begin(address); (slave) |
I2C Data Transmission | Sending and receiving data packets between MCUs. | Wire.write(byte); (send)Wire.read(); (receive) |
Design and Fabrication/h2>
I took time to learn how to programme UNo Wifi R4 inbuilt LCD display so I started with reading its datasheet.
Then tried the tutorials. with picture shown below.
Next I connected the R4 to esp32 via twi setup. Where SCL is connected to SCL and SDA to SDA and both sharing common ground. I wanted to make it such that when 1 is kkeyed into my computer, it will show a certain image. and 0 another image.
Programming Approach
The development of the project's codebase was iterative. I started with simple blink tests and gradually integrated the communication protocols. My strategy was to write modular code, enabling easy testing and debugging of individual components before bringing them together into a cohesive program.
Source Code and Design Files
For R4
#include "Arduino_LED_Matrix.h" #includeFor Esp32ArduinoLEDMatrix matrix; const uint32_t happy[] = { 0x19819, 0x80000001, 0x81f8000 }; const uint32_t heart[] = { 0x3184a444, 0x44042081, 0x100a0040 }; bool toggle = false; // Toggle state void setup() { Serial.begin(115200); matrix.begin(); Wire.begin(4); // Set up I2C on address 4 Wire.onReceive(receiveEvent); // Register I2C receive event } void loop() { if (toggle) { matrix.loadFrame(happy); } else { matrix.loadFrame(heart); } delay(500); // Delay for visibility } void receiveEvent(int bytes) { while(Wire.available()) { // loop through all but the last byte x = Wire.read(); // receive byte as a character } toggle = !toggle; // Toggle the display on each signal received }
#include#define I2C_ADDRESS 4 // I2C address of the UNO R4 WiFi void setup() { Serial.begin(115200); // Start the serial communication Wire.begin(); // Join I2C bus as master Serial.println("Send '1' to toggle UNO R4 WiFi LED display."); } void loop() { if (Serial.available()) { // Check if data is available to read char c = Serial.read(); // Read the incoming character if (c == '1') { Wire.beginTransmission(I2C_ADDRESS); // Start transmission to device Wire.write(1); // Send the toggle command, value '1' Wire.endTransmission(); // End transmission Serial.println("Toggle command sent."); } } delay(10); // Small delay to prevent flooding }
Project 'Hero Shot'
In the video, you can see that when i type in 1 into my serial prompt, it will change the display.
v3: Instructor Request for Website to control esp32 instead of using twi only
instructor requested me to redo the assignment so that I can use website to control the esp32.
So I started writing the html where I have a slider and button. then I wrote the JS to listen to slider and button clicks. then i used websocket to send data to the wifi address from my esp32.
Next I started to install the libraries needed in my arduino ide and uploaded my arduino code and upload code to esp32 check my wifi ip address.
Next I start to test the buttons and sliders with my browser and ensure my devices connect to same wifi and ip address are correct.
Encountered Problems and Solutions
Took some time to understand the const uint32_t happy[] = {
0x19819,
0x80000001,
0x81f8000
};.
Found articles explaining that In hexadecimal, each digit represents 4 bits. Therefore, each uint32_t can represent up to 32 bits. In the context of an LED matrix, each bit corresponds to the state of an individual LED: a 1 and 0 is used to control state.
I previously also had programmed and document how I used an ATTINY1614 which I designed and made it communicate with arduino, where when my ATTINY1614 is pressed, it will light up and also send signal to arduino and arduino will send signal to PC same via TWI, but as I did not use my own milled programmer, I redo it now using ESP32. Hope this ESP32 version suffices!